<template>

    <navBar/>

    <div class="hanghang-box-0" style="width:100%;">
        <div style="display:flex; justify-content:center">
            <div class="container-2">
                <div class=" hanghang-bg" style="min-height: 886px;">
                    <div class="hanghang-content">
                        <div class="hanghang-za" style="margin-bottom:50px;">
                            <div class="hanghang-za-title">
                                {{book.categoryTitle}}
                            </div>
                            <div class="hanghang-shu-content">
                                <div class="hanghang-shu-content-img">
                                    <!-- <img src="@/static/images/book/5d51240f9486c.jpg"> -->
                                    <img :src="util.checkFileUrl(book.image)">
                                </div>
                                <div class="hanghang-shu-content-font">
                                    <p>
                                        书名：{{book.title}}
                                    </p>
                                    <p>
                                        作者：{{book.author}}
                                    </p>
                                    <p>
                                        分类：{{book.categoryTitle}}
                                    </p>
                                    <p>
                                        豆瓣评分：{{book.grade}}
                                    </p>
                                    <p>
                                        简介：
                                    </p>
                                    <p>
                                    </p>
                                    <p>
                                        <rich-text
                                          class="content"
                                          :nodes="book.content"
                                        />
                                    </p>
                                    <p>
                                    </p>
                                </div>
                                <div class="clearFloat">
                                </div>
                            </div>
                            <div class="hanghang-box" style="margin-bottom:15px;">
                                <div class="hanghang-shu-content-btn">
                                    <h4 style="font-size:16px;">
                                        下载地址 ↓（
                                        <span style="color:#f00">
                                            注：如果下载失败，请联系小编，QQ：2338856113
                                        </span>
                                        ）
                                    </h4>
                                    <a href="https://pan.baidu.com/s/1X2YVhhS_btp544C3LF8hzg" class="downloads"
                                    target="_blank">
                                        <div class="hanghang-shu-content-btns">
                                            百度网盘(提取码:6666)
                                        </div>
                                    </a>
                                </div>
                                <div class="clearFloat">
                                </div>
                                
                            </div>
                            <!--<div class="hanghang-za-title">作者简介</div><div class="hanghang-za-content"></div><div class="hanghang-za-title">目录</div><div class="hanghang-za-content"></div><div class="hanghang-za-title">目录</div>-->
                            <!---->
                        </div>

                        <div class="" style="display: flex; width: 100%; justify-content: center;">
                            <view class="back-btn" @tap="toBookListing">
                                <div class="hanghang-shu-content-btns">
                                    返回
                                </div>
                            </view>
                        </div>
                        
                    </div>
                </div>
            </div>
        </div>

        

    </div>

    
                                
    <view class="footer">
        <div class="hanghang-box">
            @行行：QQ：2338856113
        </div>
    </view>

</template>

<script setup>
    import util from '@/utils/util.js';
    import navBar from '@/pages/components/nav-bar.vue';

    const book = ref({
      title: '',
      categoryTitle: '',
      author: '',
      grade: '',
      image: '',
      content: '',
      id: null
    });

    const currentPage = ref();
    const isCategory = ref();
    const categoryId = ref();

    onLoad((options) => {
        currentPage.value = options?.current || 1;
        isCategory.value = options?.isCategory || 0;
        categoryId.value = options?.categoryId || 0;
      // 加载公告详情
      http.request({
        url: '/shop/book/info/' + options.id,
        method: 'GET'
      })
        .then(({ data }) => {
          data.content = data.content.replace(/width=/gi, 'sss=')
          data.content = data.content.replace(/height=/gi, 'sss=')
          data.content = data.content.replace(/ \/>/gi, ' style="max-width:100% !important;display:block;" />')
          book.value = data
        })
    })

    const toBookListing = () => {
        history.back();
        return;

      // 1. 定义所有可能传递的参数及其验证规则
      const paramsConfig = {
        current: {
          value: currentPage.value,
          isValid: v => v > 1  // 只有大于1的页码才传递
        },
        size: {
          value: size.value,
          isValid: v => v > 1  // 只有大于1的页码才传递
        },
        categoryId: {
          value: categoryId.value,
          isValid: v => v && !isNaN(v)  // 非空且是有效数字
        },
        // 可以添加更多参数...
      };

      // 2. 构建有效参数对象
      const validParams = Object.entries(paramsConfig).reduce((acc, [key, {value, isValid}]) => {
        if (isValid(value)) {
          acc[key] = value;
        }
        return acc;
      }, {});

      // 3. 生成查询字符串（使用URLSearchParams自动编码）
      const queryString = new URLSearchParams(validParams).toString();

      // 4. 决定目标路径
      const basePath = isCategory.value 
        ? '/pages/index/book-category' 
        : '/pages/index/index';

      // 5. 执行跳转（优先使用redirectTo保证刷新）
      uni.navigateTo({
        url: queryString ? `${basePath}?${queryString}` : basePath
      });
    }
</script>

<style scoped lang="scss">
    @use './index.scss'; 
</style>